package cn.dancepeak.log.controller;

import cn.dancepeak.exception.BusinessException;
import cn.dancepeak.log.domain.Log;
import cn.dancepeak.log.service.ILogServiceImpl;
import cn.dancepeak.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/log")
@Slf4j
public class LogController {
    @Autowired
    private ILogServiceImpl logService;

    //1.增
    @PostMapping("/add")
    public R<Void> add(@RequestBody Log logs){
        try {
            logService.add(logs);
            return R.ok("新增成功");
        } catch (BusinessException e) {
            log.info("新增用户异常：{}",e.getMessage());
            return R.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.info("新增系统异常：{}",e.getMessage());
            return R.fail(e.getMessage());
        }
    }

}
